package com.example.common.dto;

import com.example.common.constants.ENUM_RESTFUL_COMMON_CODE;

/**
 * @author ：czx
 * @date ：Created in 2021/6/24 15:25
 * @modified By：
 */
public class ResultModel {

    private int code;

    private String message = "";

    private Object content;

    public ResultModel() {

    }

    public ResultModel(int code, String message) {
        this.code = code;
        this.message = message;
        this.content = "";
    }

    public ResultModel(int code, String message, Object content) {
        this.code = code;
        this.message = message;
        this.content = content;
    }

    public static ResultModel success(Object content) {
        return new ResultModel(0, "成功", content);
    }

    public static ResultModel success() {
        return new ResultModel(0, "成功");
    }

    public static ResultModel error(Object[] objects) {
        if (null != objects && objects.length == 2) {
            return new ResultModel(Integer.valueOf(String.valueOf(objects[0])),
                    String.valueOf(objects[1]));
        } else {
            return new ResultModel(
                    ENUM_RESTFUL_COMMON_CODE.SYSTEM_ERROR.getCode(),
                    ENUM_RESTFUL_COMMON_CODE.SYSTEM_ERROR.getMessage());
        }
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public Object getContent() {
        return content;
    }

    public void setContent(Object content) {
        this.content = content;
    }

}
